{% extends 'window.twig' %}
{% block body %}
    <div class="admin-main-container" style="margin: 10px 5px">
        <div class="group-wrapper data-view">
            <div class="tree-wrapper" style="max-height: 300px;overflow: auto;">
                {% for g in userList %}
                    <div class='group-item'>
                        <p class="group-name">
                            {{ g.group_name }}
                        </p>
                        <p class="group-user">
                            {% for u in g.user_list %}
                                <label for="g_i_{{ u.uid }}">
                                    <input type="radio" name="group_id" id="g_i_{{ u.uid }}"
                                           class="i-check uid" value="{{ u.uid }}"/>
                                    {{ u.nick_name }}
                                </label>
                            {% endfor %}
                        </p>
                    </div>
                {% else %}
                    <h3 style="text-align: center;border-bottom: solid 1px #dedede;padding-bottom: 10px;">暂无用户</h3>
                {% endfor %}
            </div>
            <div class="show-more form-inline">
                {% if showMore.more_date %}
                    <div class="form-group">
                        <label for="exampleInputEmail2">请选择过期日期:</label>
                        <input type="text" name="datetime" style="width: auto;display: inline-block;"
                               class="datetime form-control required" date-min="%y-%M-%d"
                                data-required="请选择过期日期"/>
                    </div>
                {% endif %}
            </div>
            <div class="text-right">
                <button class="btn btn-info selected">确认选择</button>
            </div>
        </div>
        <div style="height: 30px;"></div>
    </div>
{% endblock %}
{% block script %}
<link href="{{ __URL__ }}/static/assets/icheck/skins/square/_all.css" rel="stylesheet">
<style type="text/css">body{overflow: hidden;}</style>
<script type="text/javascript" src="{{ __URL__ }}/static/assets/icheck/icheck.min.js"></script>
<script type="text/javascript">
    $(function(){
        util.resize(window,400);
        var index = util.getIndex(window);
        setTimeout(function(){
            dx.iframeAuto(index);
        },100);
        $('.i-check').iCheck({
                    checkboxClass: 'icheckbox_square-blue',
                    radioClass: 'iradio_square-blue',
                    increaseArea: '20%'
                });
        $('button.selected').on('click',function(){
            var selectedUid = $('input.uid:checked').map(function(){return this.value;}).get();
            console.log(selectedUid);
            if(selectedUid.length == 0) {
                dx.msg('请先选择用户',{time:1500});
                return false;
            }
            var flag = true;
            var backData = {
                uid:selectedUid
            };
            $('input.required').each(function(){
                var _this = $(this);
                var key =_this.attr('name');
                var value =_this.val();
                if(value != '')backData[key] = value
                if(flag == false) return;
                if(value == ''){
                    dx.msg(_this.attr('data-required'),{time:1500});
                    flag = false;
                }
            });
            if(flag == false) return flag;
            util.close(window,backData);
           return false;
        });
    });
</script>
{% endblock %}